// Learn cc.Class:
//  - [Chinese] https://docs.cocos.com/creator/manual/zh/scripting/class.html
//  - [English] http://docs.cocos2d-x.org/creator/manual/en/scripting/class.html
// Learn Attribute:
//  - [Chinese] https://docs.cocos.com/creator/manual/zh/scripting/reference/attributes.html
//  - [English] http://docs.cocos2d-x.org/creator/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
//  - [Chinese] https://docs.cocos.com/creator/manual/zh/scripting/life-cycle-callbacks.html
//  - [English] https://www.cocos2d-x.org/docs/creator/manual/en/scripting/life-cycle-callbacks.html

cc.Class({
    extends: cc.Component,

    properties: {
        // foo: {
        //     // ATTRIBUTES:
        //     default: null,        // The default value will be used only when the component attaching
        //                           // to a node for the first time
        //     type: cc.SpriteFrame, // optional, default is typeof default
        //     serializable: true,   // optional, default is true
        // },
        // bar: {
        //     get () {
        //         return this._bar;
        //     },
        //     set (value) {
        //         this._bar = value;
        //     }
        // },
        labelRank:{
            default:null,
            type:cc.Label
        },
        labelName:{
            default:null,
            type:cc.Label
        },
        labelWin:{
            default:null,
            type:cc.Label
        },
        labelLost:{
            default:null,
            type:cc.Label
        },
        labelWhole:{
            default:null,
            type:cc.Label
        },
        faceSprite:{
            default:null,
            type:cc.Sprite
        }
    },

    // LIFE-CYCLE CALLBACKS:

    // onLoad () {},

    start () {

    },

    // update (dt) {},

    tryGetHeight(){
        return this.node.height
    },

    updateItem(info){
        this.itemInfo = info
        let rank = info.rank
        let name = info.name
        let winCoin = info.win
        let wholeCoin = info.total
        let lostCoin = wholeCoin - winCoin
        let img = info.img

        this.labelRank.string = rank
        this.labelName.string = name
        this.labelWin.string = cc.gg.gameDataUtil.getStringOfRupee(winCoin)
        this.labelLost.string = cc.gg.gameDataUtil.getStringOfRupee(lostCoin)
        this.labelWhole.string = cc.gg.gameDataUtil.getStringOfRupee(wholeCoin)

        this._setFace(img)
    },

    _setFace:function (url) {
        cc.gg.logicUtil.initHead(url,this.faceSprite)
    }
});
